package com.third.clock.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.util.Log;

import com.third.clock.ClockApplication;
import com.third.clock.common.Contants;
import com.third.clock.service.ClockService;
import com.third.clock.service.JobHandlerService;
import com.third.clock.service.RemoteService;

/**
 * Created by Administrator on 2018/7/21 0021.
 */

public class SystemBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.e("m_tag","onReceive"+intent.getAction());
        if(intent==null) return;
        if(intent.getAction()==null) return;
        String action=intent.getAction();
        if(action.equals(Intent.ACTION_BOOT_COMPLETED)) {
            if(Build.VERSION.SDK_INT>=26){
                context.startForegroundService(new Intent(context, ClockService.class));
                context.startForegroundService(new Intent(context, RemoteService.class));
            }else {
                context.startService(new Intent(context, ClockService.class));
                context.startService(new Intent(context, RemoteService.class));
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                context.startService(new Intent(context, JobHandlerService.class));
            }
        }else if(action.equals(Contants.ACTION_RTC_HEART)){
            if(mObserve!=null) mObserve.onEvent(intent);
        }else if(action.equals(Contants.ACTION_RTC_LOCATION)){
            if(mObserve!=null) mObserve.onEvent(intent);
        }
    }

    public static  void setObserve(onSystemBroadcastReceiverObserve observe){
        mObserve=observe;
    }

    private static onSystemBroadcastReceiverObserve mObserve;

    public interface onSystemBroadcastReceiverObserve{
        void onEvent(Intent intent);
    }

}
